﻿using ST.Library.UI.NodeEditor;
using STNode_A2B.DataType;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinNodeEditorDemo.Blender;

namespace STNode_A2B.STNodes
{
    [STNode("A2B")]
    public class STNode_Processor : STNode
    {
        private ColorMixType _MixType;
        [STNodeProperty("MixType", "This is MixType")]
        public ColorMixType MixType
        {
            get { return _MixType; }
            set
            {
                _MixType = value;
                m_ctrl_select.Enum = value; //当属性被赋值后 对应控件状态值也应当被修改
            }
        }
        public enum ColorMixType
        {
            PC,
            CH347
        }

        private string _nodeName = "Processor";
        [STNodeProperty("Title", "Title")]
        public string NodeName
        {
            get { return _nodeName; }
            set
            {
                this._nodeName = value;
                this.Title = this._nodeName;
            }
        }

        private STNodeSelectEnumBox m_ctrl_select;  //自定义控件
       
        protected override void OnCreate()
        {
            base.OnCreate();
            this.TitleColor = Color.FromArgb(200, Color.DarkKhaki);
            this.Title = "Processor";
            this.AutoSize = false;
            this.Size = new Size(140, 80);
            this.OutputOptions.Add("IIC", typeof(IIC), false);
            this.OutputOptions.Add(STNodeOption.Empty);
            this.OutputOptions.Add("SPI", typeof(SPI), false);

            m_ctrl_select = new STNodeSelectEnumBox();
            m_ctrl_select.DisplayRectangle = new Rectangle(10, 21, 120, 18);
            m_ctrl_select.Enum = this._MixType;
            m_ctrl_select.ValueChanged += (s, e) => this._MixType = (ColorMixType)m_ctrl_select.Enum;
            this.Controls.Add(m_ctrl_select);
        }

        protected override void OnOwnerChanged()
        {
            base.OnOwnerChanged();
          
            if (this.Owner != null)
            {
                this.Owner.SetTypeColor(typeof(IIC), Color.DarkCyan);
                this.Owner.SetTypeColor(typeof(SPI), Color.GreenYellow);
            }        
        }
    }
}
